package cn.lingyangwl.agile.common.core.exception.enums;

import cn.lingyangwl.framework.tool.core.exception.BaseError;
import lombok.Getter;
import org.springframework.http.HttpStatus;

/**
 * 全局错误码枚举
 * 0-999 系统异常编码保留, 主要是不想和http请求状态码重复比如200,404等 1000 ~ 100000
 * 虽然说，HTTP 响应状态码作为业务使用表达能力偏弱，但是使用在系统层面还是非常不错的
 *
 * 类比
 * 110000 ~ 119999: 基础设施服务
 * 120000 ~ 129999: 支付服务
 * @author shenguangyang
 */
@Getter
public enum GlobalErrorEnum implements BaseError {
    SUCCESS("成功", 1, HttpStatus.OK),
    FAIL("系统异常,请联系管理员", 2, HttpStatus.BAD_REQUEST),

    SERVICE_OFFLINE("服务下线，暂时不可用", 502, HttpStatus.BAD_GATEWAY),
    SERVICE_ERROR("服务不可用，过载保护", 503, HttpStatus.SERVICE_UNAVAILABLE),

    /**
     * 无权限访问
     */
    ACCESS_DENIED("无权限访问", 403, HttpStatus.FORBIDDEN),
    DATA_SURCHARGE("数据越权", 403, HttpStatus.FORBIDDEN),
    PATH_NOT_PATH("请求路径不存在", 404, HttpStatus.NOT_FOUND),

    /**
     * 验证码
     */
    CODE_TO_ERROR("接收号码不合规", 1301, HttpStatus.BAD_REQUEST),
    CODE_LIMITED("验证码发送过快", 1302, HttpStatus.TOO_MANY_REQUESTS),
    CODE_ERROR("验证码错误! ", 1303, HttpStatus.BAD_REQUEST),
    CODE_CAPTCHA_ERROR("图形验证码错误", 1304, HttpStatus.BAD_REQUEST),

    /**
     * check
     */
    ACCESS_LIMIT_REACHED("非法请求!", 1402, HttpStatus.BAD_REQUEST),
    REQUEST_ILLEGAL("访问太频繁!", 1403, HttpStatus.TOO_MANY_REQUESTS),
    PARAM_ERROR("参数错误",1404, HttpStatus.BAD_REQUEST),

    REPEAT_SUBMIT("请不要重复提交", 1501, HttpStatus.BAD_REQUEST),

    /**
     * 调用其他系统异常错误代码
     */
    INVOKE_OUTSIDE_SYSTEM("调用外部系统异常", 1601, HttpStatus.BAD_REQUEST),

    /**
     * mq相关错误
     */
    MQ_LISTENER_ERROR("mq消费异常", 1900, HttpStatus.BAD_REQUEST),

    /**
     * 应用模块
     */
    USER_NO_HAS_APP_MODULES("您未归属于任何应用模块, 请联系管理员", 2000, HttpStatus.BAD_REQUEST),

    /**
     * 操作失败
     */
    OPERATION_FAIL_CREATE("新增失败", 3000, HttpStatus.BAD_REQUEST),
    OPERATION_FAIL_DELETE("删除失败", 3001, HttpStatus.BAD_REQUEST),
    OPERATION_FAIL_UPDATE("修改失败", 3002, HttpStatus.BAD_REQUEST),
    OPERATION_FAIL_SELETE("记录不存在", 3003, HttpStatus.NOT_FOUND),


    /**
     * 应用相关
     */
    APP_PARAM_MISS("缺失应用参数", 4000, HttpStatus.BAD_REQUEST),

    /**
     * 签名相关
     */
    SIGN_CHECK_FAIL("签名验证失败", 5000, HttpStatus.UNAUTHORIZED),
    SIGN_GEN_FAIL("签名生成失败", 5001, HttpStatus.BAD_REQUEST),
    SIGN_URL_TIMEOUT("签名url超时", 5002, HttpStatus.UNAUTHORIZED),

    /**
     * 导出导入失败
     */
    EXCEL_IMPORT_FAIL("{}", 6000, HttpStatus.OK),

    // ============================================== 具体服务中的错误代码
    /**
     * 基础设施服务中
     */
    DATA_GROUP_USED( "当前组已被引用, 不能删除", 110000,  HttpStatus.OK),

    ;
    private final String message;

    private final Integer code;
    private final HttpStatus status;


    GlobalErrorEnum(String message, Integer code, HttpStatus status) {
        this.status = status;
        this.code = code;
        this.message = message;
    }

    public String getName() {
        return this.name();
    }

    public String getOutputName() {
        return this.name();
    }

    public String toString() {
        return this.getName();
    }
}
